<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        label::before{
            padding: 3px;
            background-clip: content-box;
            box-sizing: border-box;
            content: "";
            display: inline-block;
            width: 20px;
            height: 20px;
            border: 2px solid royalblue;
            border-radius: 50%;
            margin-right: 10px;
        }
        input:checked+label::before {
            background-color: royalblue;
        }
        .con{
            margin-top: 50px;
        }
        .con input{
            display: none;
        }
    </style>
</head>
<body>
    <form action="" method="get" id="myform">
        姓名<input type="text" name="username" id="username" />
        <input type="checkbox" name="hobby" value="football" id="hobby" checked />足球
        <input type="button" value="提交" id="sub" />
    </form>


    <div>
        <input type="radio" name="sex" value="male" />男
        <input type="radio" name="sex" value="female" />女        
    </div>

    <div class="con">
        <input type="radio" id="radio1" name="basketball">
        <label for="radio1">篮球</label>
    </div>

</body>
<script>
    /**
     * 1.关注元素的事件，属性，方法
     * 选择合理的事件，属性，方法的组合形式
     * 实现对应的逻辑业务
     * 
    */

    let $ = document.querySelector.bind(document)

    let username = $('#username')
    let hobby = $('#hobby')
    let sub = $('#sub')
    let myform = $('#myform')

    hobby.addEventListener('change', (e) => {
        console.log(e)
    })

    username.focus()

    sub.onclick = function () {
        if(username.value == '') {
            alert('用户名不能为空！！')
        }
        myform.submit()
    }
</script>
</html>